class Solution(object):
    def isPalindrome(self, s):
        """
        :type s: str
        :rtype: bool
        """
        l = 0
        r = len(s) - 1
        while l <= r:
            print('l is %d; r is %d' % (l, r))
            if 65 <= ord(s[l]) <=90 or 97 <= ord(s[l]) <= 122 or 48 <= ord(s[l]) <= 57:
                pass
            else:
                l += 1
                continue
            if 65 <= ord(s[r]) <=90 or 97 <= ord(s[r]) <= 122 or 48 <= ord(s[r]) <= 57:
                pass
            else:
                r -= 1
                continue
            if s[l] == s[r] \
                    or (ord(s[l]) == ord(s[r]) + 32  and 65 <= ord(s[l]) <= 90 and 97 <= ord(s[r]) <= 122)\
                    or (ord(s[l]) == ord(s[r]) - 32 and 97 <= ord(s[l]) <= 122 and 65 <= ord(s[r]) <= 90):
                l += 1
                r -= 1
            else:
                return False
        return True


class Solution(object):
    def isPalindrome(self, s):
        """
        :type s: str
        :rtype: bool
        """
        l, r = 0, len(s)-1
        while l < r:
            while l < r and not s[l].isalnum():
                # isalnum() 验证是否是字符或数字
                l += 1
            while l < r and not s[r].isalnum():
                r -= 1
            if s[l].lower() != s[r].lower():
                return False
            l +=1
            r -= 1
        return True

test = Solution()
print(test.isPalindrome("A man, a plan, a canal: Panama"))